//
//  MKTChatItemsTabContentView.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2021/7/9.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKTChatItemsTabContentView.h"

@implementation UITabBarItem_MKTChatMsgMultiItemTab
- (NSString *)title{
    return self.multiItemTab.title;
}
@end

@interface MKTChatItemsTabContentView()
@end

@implementation MKTChatItemsTabContentView
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.itemsView = [[MKTChatItemsView alloc] init];
        [self.contentView addSubview:self.itemsView];
    }
    return self;
}
+ (Class)tabBarItemClass{
    return [UITabBarItem_MKTChatMsgMultiItemTab class];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.itemsView.frame = bounds;
}
- (void)setMultiItemTab:(MKTChatMsgMultiItemTab *)multiItemTab{
    _multiItemTab = multiItemTab;
    UITabBarItem_MKTChatMsgMultiItemTab *tabBarItem = self.tabBarItem;
    tabBarItem.multiItemTab = self.multiItemTab;
}
- (void)reloadData{
    self.itemsView.itemslist = self.multiItemTab.itemslist;
    [self.itemsView reloadData];
}
- (void)tabBarContentViewDidAppear:(BOOL)animated{
    [self reloadData];
}
- (CGSize)sizeThatFits:(CGSize)size{
    CGSize s = [self.itemsView sizeThatFits:size];
    return s;
}

@end

@implementation MKUITabBarItemCollectionViewCell_MKTChatMsgMultiItemTab
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.tabBarItemButton.contentInsets = UIEdgeInsetsZero;
        self.tabBarItemButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        self.subtitleLabel = [[UILabel alloc] init];
        self.subtitleLabel.textAlignment = NSTextAlignmentCenter;
        self.subtitleLabel.numberOfLines = 1;
        self.subtitleLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.subtitleLabel];
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.tabBarItemButton,self.subtitleLabel] constraintParam:(MKUIFlowLayoutConstraintParam_V_T_C) contentInsets:UIEdgeInsetsMake(5, 5, 10, 5) interitemSpacing:2];
    }
    return self;
}
- (void)customLayoutSubviews{
    [super customLayoutSubviews];
    CGRect bounds = self.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (void)customReloadCellModel{
    [super customReloadCellModel];
    UITabBarItem_MKTChatMsgMultiItemTab *tabBarItem =  (UITabBarItem_MKTChatMsgMultiItemTab *)self.tabBarItem;
    MKTChatMsgMultiItemTab *itemTab = tabBarItem.multiItemTab;
    self.subtitleLabel.text = itemTab.subtitle.text;
    switch (itemTab.subtitle.style) {
        case MKTChatLabelValueStyleNormal:
            self.subtitleLabel.textColor = [UIColor grayColor];
            break;
        case MKTChatLabelValueStyleAccess:
            self.subtitleLabel.textColor = [UIColor greenColor];
            break;
        case MKTChatLabelValueStyleWarning:
            self.subtitleLabel.textColor = [UIColor redColor];
            break;
        default:
            self.subtitleLabel.textColor = [UIColor grayColor];
            break;
    }
}
- (CGSize)customSizeThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
@end
